<template>
    <div>
        <el-card class="!border-none" shadow="never">
            <el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
                <el-form-item label="用户ID">
                    <el-input
                            class="w-[150px]"
                            v-model="queryParams.uuid"
                            placeholder="请输入用户ID"
                            clearable
                            @keyup.enter="resetPage"
                    />
                </el-form-item>
                <el-form-item label="用户昵称/手机号">
                    <el-input
                            class="w-[280px]"
                            v-model="queryParams.user_keyword"
                            placeholder="请输入用户昵称/手机号"
                            clearable
                            @keyup.enter="resetPage"
                    />
                </el-form-item>
                <el-form-item label="团长搜索">
                    <el-input
                            class="w-[280px]"
                            v-model="queryParams.name"
                            placeholder="请输入用户ID/昵称/手机号"
                            clearable
                            @keyup.enter="resetPage"
                    />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none mt-4" shadow="never">
            <el-tabs class="demo-tabs" v-model="type" @tab-click="handleTabclick">
                <el-table size="large" v-loading="pager.loading" :data="pager.lists" style="width: 100%">
                    <el-table-column label="用户ID / 手机号 / 昵称" prop="name" min-width="180">
                        <template #default="{ row }">
                            {{ row.uuid }} / {{ row.phone }} / {{ row.nickname }}
                        </template>
                    </el-table-column>
                    <el-table-column label="团长ID / 手机号 / 昵称" prop="name"  min-width="150">
                        <template #default="{ row }">
                            暂无团长信息
<!--                            {{ row.uuid }}/{{ row.phone }}/{{ row.nickname }}-->
                        </template>
                    </el-table-column>
                    <el-table-column label="联系电话" prop="name"  min-width="100">
                        <template #default="{ row }">
                            {{ row.phone }}
                        </template>
                    </el-table-column>
                    <el-table-column label="投诉凭证" prop="name"  min-width="150">
                        <template #default="{ row }">
                            <template v-for=" item in row.image">
                                <div style="display: inline-block">
                                    <image-contain
                                        v-if="item"
                                        :src="item"
                                        :width="45"
                                        :height="45"
                                        :preview-src-list="[item]"
                                        preview-teleported
                                        fit="contain"
                                    />
                                </div>
                            </template>
                        </template>
                    </el-table-column>
                    <el-table-column label="投诉状态" prop="name"  min-width="150">
                        <template #default="{ row }">
                            <el-tag class="ml-2" :type="['success', 'error'][row.status-1]"> {{ complaint_state.map(res => res.name)[row.status-1] }}</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column label="投诉内容" prop="name"  min-width="150">
                        <template #default="{ row }">
                            {{ row.created_at }}
                        </template>
                    </el-table-column>
                    <el-table-column label="操作面板" min-width="160" fixed="right">
                        <template #default="{ row }">
                            <el-button type="success" @click="userDelete(row.id)">
                                处理完成
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="flex justify-end mt-4">
                    <pagination v-model="pager" @change="getLists" />
                </div>
            </el-tabs>
        </el-card>
    </div>
</template>
<script lang="ts" setup>
    import { getUserComplainList, complainHandle } from '@/api/afterSale'
    import { usePaging } from '@/hooks/usePaging'
    import feedback from "@/utils/feedback";
    import router, { getRoutePath } from '@/router'

    const complaint_state = [
        {
            id: 1,
            name: '已处理'
        },
        {
            id: 2,
            name: '未处理'
        },
    ];

    const queryParams = reactive({
        uuid: '',
        user_keyword: '',
        content: '',
        status: '',
        time: '',
        start_time: '',
        end_time: '',
    });

    const { pager, getLists, resetPage, resetParams } = usePaging({
        fetchFun: getUserComplainList,
        params: queryParams
    });

    getLists();

    // 删除优惠卷
    const userDelete = async (id: number) => {
        await feedback.confirm('确定处理完成？');
        complainHandle({uuid: id});
        getLists()
    };

</script>
